package com.xunwulian.cmpp.client.service;

import com.google.gson.Gson;
import com.xunwulian.base.constant.CommonErrorCode;
import com.xunwulian.cmpp.client.handler.CmppClient;
import com.xunwulian.cmpp.pdu.Submit;
import com.xunwulian.api.dto.BaseResponse;
import com.xunwulian.dubbo.iface.CmppSmsAPI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by liyankai on 2017/2/17.
 */
@Service
public class CmppSmsApiImpl implements CmppSmsAPI {

    protected static final Logger logger = LoggerFactory.getLogger(CmppSmsApiImpl.class);

    @Autowired
    private CmppClient client;

    @Override
    public BaseResponse sendCmppSms(Submit submit) {

        logger.info("sendCmppSms:" + new Gson().toJson(submit));
        if (client != null) {
            client.sendMessage(submit);
        } else {
            return new BaseResponse(CommonErrorCode.E_CLIENT_NOT_INITIALIZED.getDesc(),
                    CommonErrorCode.E_CLIENT_NOT_INITIALIZED.getDesc());
        }
        return new BaseResponse();
    }
}
